﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniversalDataAccess.BusinessEntities;

namespace UniversalDataAccess.DataAccess
{
    public class EducationalDivisionsDataAccess : DivisionsDataAccess
    {
        public EducationalDivisionsDataAccess(String dbName, String conn, Boolean usePredefinedMetadata)
            : base(dbName, conn, usePredefinedMetadata)
        {
        }

        public List<EducationalDivision> SelectEducationalDivisionsList()
        {
            List<Division> divList = SelectDivisionsList();

            var res = (from div in divList
                       select new EducationalDivision
                       {
                           DataBaseName = dataBaseName,
                           CLASS_ID = div.CLASS_ID,
                           EXT_ID = div.EXT_ID,
                           ID = div.ID,
                           NAME = div.NAME,
                           PARENT_ID = div.PARENT_ID,
                           BOSS_ID = div.BOSS_ID,
                           DATE_CREATED = div.DATE_CREATED,
                           DESCRIPTION = div.DESCRIPTION
                       }).ToList();

            return res;
        }

        public EducationalDivision SelectEducationalDivisionBy_Id(int Id)
        {
            try
            {
                Division basePart = SelectDivisionBy_Id(Id);

                var res = new EducationalDivision
                           {
                               DataBaseName = dataBaseName,
                               CLASS_ID = basePart.CLASS_ID,
                               EXT_ID = basePart.EXT_ID,
                               ID = basePart.ID,
                               NAME = basePart.NAME,
                               PARENT_ID = basePart.PARENT_ID,
                               BOSS_ID = basePart.BOSS_ID,
                               DATE_CREATED = basePart.DATE_CREATED,
                               DESCRIPTION = basePart.DESCRIPTION,
                           };

                return res;
            }
            catch
            {
                throw new Exception("Error while SelectEducationalDivisionById");
            }
        }

        public void InsertEducationalDivision(EducationalDivision edDivision, ref int generated_Id)
        {
            try
            {
                InsertDivision(edDivision, ref generated_Id);
            }
            catch (Exception ex)
            {
                throw new Exception("Error while InsertEducationalDivision");
            }
        }

        public void UpdateEducationalDivision(EducationalDivision edDivision)
        {
            try
            {
                UpdateDivision(edDivision);
            }
            catch (Exception ex)
            {
                throw new Exception("Error while UpdateEducationalDivision");
            }
        }

        public void DeleteEducationalDivision(EducationalDivision edDivision)
        {
            try
            {
                DeleteDivision(edDivision);
            }
            catch (Exception ex)
            {
                throw new Exception("Error while DeleteEducationalDivision");
            }
        }
    }
}
